package com.ruoyi.service.impl;

import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import com.ruoyi.common.utils.StringUtils;
import org.springframework.transaction.annotation.Transactional;
import com.ruoyi.domain.MakerList;
import com.ruoyi.mapper.QualitystandardMapper;
import com.ruoyi.domain.Qualitystandard;
import com.ruoyi.service.IQualitystandardService;

/**
 * 质检标准Service业务层处理
 * 
 * @author 牢博
 * @date 2024-10-30
 */
@Service
public class QualitystandardServiceImpl implements IQualitystandardService 
{
    @Autowired
    private QualitystandardMapper qualitystandardMapper;

    /**
     * 查询质检标准
     * 
     * @param id 质检标准主键
     * @return 质检标准
     */
    @Override
    public Qualitystandard selectQualitystandardById(String id)
    {
        return qualitystandardMapper.selectQualitystandardById(id);
    }

    /**
     * 查询质检标准列表
     * 
     * @param qualitystandard 质检标准
     * @return 质检标准
     */
    @Override
    public List<Qualitystandard> selectQualitystandardList(Qualitystandard qualitystandard)
    {
        return qualitystandardMapper.selectQualitystandardList(qualitystandard);
    }

    /**
     * 新增质检标准
     * 
     * @param qualitystandard 质检标准
     * @return 结果
     */
    @Transactional
    @Override
    public int insertQualitystandard(Qualitystandard qualitystandard)
    {
        int rows = qualitystandardMapper.insertQualitystandard(qualitystandard);
        insertMakerList(qualitystandard);
        return rows;
    }

    /**
     * 修改质检标准
     * 
     * @param qualitystandard 质检标准
     * @return 结果
     */
    @Transactional
    @Override
    public int updateQualitystandard(Qualitystandard qualitystandard)
    {
        qualitystandardMapper.deleteMakerListByStandardId(qualitystandard.getId());
        insertMakerList(qualitystandard);
        return qualitystandardMapper.updateQualitystandard(qualitystandard);
    }

    /**
     * 批量删除质检标准
     * 
     * @param ids 需要删除的质检标准主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteQualitystandardByIds(String[] ids)
    {
        qualitystandardMapper.deleteMakerListByStandardIds(ids);
        return qualitystandardMapper.deleteQualitystandardByIds(ids);
    }

    /**
     * 删除质检标准信息
     * 
     * @param id 质检标准主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteQualitystandardById(String id)
    {
        qualitystandardMapper.deleteMakerListByStandardId(id);
        return qualitystandardMapper.deleteQualitystandardById(id);
    }

    /**
     * 新增物料档案信息
     * 
     * @param qualitystandard 质检标准对象
     */
    public void insertMakerList(Qualitystandard qualitystandard)
    {
        List<MakerList> makerListList = qualitystandard.getMakerListList();
        String id = qualitystandard.getId();
        if (StringUtils.isNotNull(makerListList))
        {
            List<MakerList> list = new ArrayList<MakerList>();
            for (MakerList makerList : makerListList)
            {
                makerList.setStandardId(Long.parseLong(id));
                list.add(makerList);
            }
            if (list.size() > 0)
            {
                qualitystandardMapper.batchMakerList(list);
            }
        }
    }
}
